import { drizzle } from "drizzle-orm/postgres-js"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import postgres from "postgres"
import dotenv from "dotenv"

 dotenv.config();

const connectionString = process.env.DATABASE_URL || ''
// 尝试创建数据库
const sql = postgres(connectionString, { max: 1 })
const db = drizzle(sql)

async function main() {
  console.log("Running migrations...")
  await migrate(db, { 
    migrationsFolder: "server/drizzle",
    migrationsTable: "migrations",
    migrationsSchema: "drizzle"
  })
  console.log("Migrations completed!")
  process.exit(0)
}

main().catch((err) => {
  console.error("Migration failed:", err)
  process.exit(1)
})